package com.apes.fn.server.praticalFunction.model;

import com.alibaba.fastjson.JSONObject;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.MapUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.party.repository.PartyRoleRepository;
import com.apes.scm.masterdata.product.model.Classify;
import com.apestech.framework.json.JSON;
import com.apestech.framework.util.StringUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;
import org.springframework.util.StringUtils;

import javax.persistence.*;
import java.util.*;

/**
 * Created by lishikun on 2021/6/22 10:53
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CommodityExpandConfig.CONST_TABLE_NAME)
public class CommodityExpandConfig extends BaseModel {
    public static final String CONST_TABLE_NAME = "commodity_expand_config";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "商品过滤条件",prefix="1",padding = 6)
    @Comment("编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "smart_accessories_config_id", referencedColumnName = "id")
    @Comment("智选配置设置")
    private SmartAccessoriesConfig smartAccessoriesConfig;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "filterSource", referencedColumnName = "id")
    private Enumeration filterSource; //筛选来源：( basicAttributes:基础属性; extendAttributes:扩展属性;)

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "last_classify_id", referencedColumnName = "id")
    @Comment("末级品类")
    private Classify lastClassify;

    @Column(name = "sort", length = 250)
    @Comment("排序字段")
    private String sort;

    @Column(name="filter_conditions", length = 4000)
    @Comment("筛选条件")
    private String filterConditions;

    @Column(name="filter_show_name", length = 4000)
    @Comment("筛选字段名称")
    private String filterShowName;

    @Transient
    private JSONObject filterCondition;  // 筛选条件

    public String getFilterConditions() {
        return null;
    }

    public JSONObject getFilterCondition() {
        if (this.filterCondition != null) return this.filterCondition;
        return JSONObject.parseObject(filterConditions);

    }
}
